package com.liang.hashmap;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;


public class HashMapDemo {
    public static void main(String[] args) {
        HashMap<Student, String> hm = new HashMap<>();

        Student stu1 = new Student("xiaomei",22);
        Student stu2 = new Student("xiaohong",23);
        Student stu3 = new Student("xiaoming",24);
        Student stu4 = new Student("xiaomei",22);

        hm.put(stu1, "上海");
        hm.put(stu2, "北京");
        hm.put(stu3, "天津");
        hm.put(stu4, "河北");

        System.out.println(hm);
        System.out.println("===========================");


        /*hm.forEach(new BiConsumer<Student, String>() {
            @Override
            public void accept(Student student, String s) {
                System.out.println(student+"---"+s);
            }
        });*/

        hm.forEach((stu,s)-> System.out.println(stu+"---"+s));

        System.out.println("===========================");

        Set<Student> students = hm.keySet();
        for (Student student : students) {
            String s = hm.get(student);
            System.out.println(student+"---"+s);
        }


        System.out.println("===========================");

        Set<Map.Entry<Student, String>> entries = hm.entrySet();

        for (Map.Entry<Student, String> entry : entries) {
            Student key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key+"---"+value);
        }
    }
}
